<?php
namespace app\serveruser\validate;
use \app\manage\validate\BaseValidate;
/**
 * 应用管理的验证类
 * @author adv30 <adv30@126.com> 2017年6月2日10:59:54
 */
class Auth extends BaseValidate
{
    // 是否使用true基础的验证规则
    // protected $useBaseRules = false;
    protected $rule = [
        'id' => ['integer', 'gt' => '0'],
        'name' => ['length' => '2,20'],
        'app_name' => ['max' => '128'],
        'server' => ['length' => '2,32'],
        'module' => ['length' => '2,32'],
        'controller' => ['length' => '2,32'],
        'action' => ['length' => '2,32'],
        'other_check' => ['max' => '512'],
        'merge_auth' => ['length' => '3,128'],
        'role_id' => ['integer', 'gt' => '0'],
        'auth_ids' => ['regex' => '^(\d)+(,\d+)*'],
        'auth_id' => ['integer', 'gt' => '0'],
        'ids' => ['regex' => '^(\d)+(,\d+)*'],
        'roles' => ['min' => '2']
    ];
    protected $message = [
        'name.require' => '必须填写应用名称',
        'name.length' => '应用名称的长度应在2-20个字符',
    ];
    protected $scene = [
        'stop' => ['id'],
        'start' => ['id'],
        'add' => ['name', 'app_name', 'server', 'module', 'controller', 'action', 'other_check', 'merge_auth'],
        'edit' => ['id', 'name', 'app_name', 'server', 'module', 'controller', 'action', 'other_check', 'merge_auth'],
        'list' => ['page', 'list_rows'],
        'addAuthByRole' => ['role_id', 'auth_id'],
        'addAuthsByRole' => ['role_id', 'auth_ids'],
        'removeAuthsByRole' => ['role_id', 'auth_ids'],
        'stopByRole' => ['role_id'],
        'startByRole' => ['role_id'],
        'listByRole' => ['role_id', 'page', 'list_rows'],
        'treeByRole' => ['role_id'],
        'listByIds' => ['ids'],
        'getAuthsByRoles' => ['roles'],
        'roleByAuth' => ['auth_id']
    ];
}
